package com.sqltoy.helloworld.service.impl;

import java.util.Map;

import org.sagacity.sqltoy.dao.LightDao;
import org.sagacity.sqltoy.model.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sqltoy.helloworld.dto.OrderInfoVO;
import com.sqltoy.helloworld.entity.OrderInfo;
import com.sqltoy.helloworld.service.OrderInfoService;

/**
 * 订单服务逻辑实现
 * 
 * @author zhongxuchen
 * @date 2025/2/5
 */
@Service("orderInfoService")
public class OrderInfoServiceImpl implements OrderInfoService {
	// 功能定义
	@Autowired
	LightDao lightDao;

	// 所有单表操作对象化完成，类似jpa
	@Override
	@Transactional
	public void createOrderInfo(OrderInfoVO orderInfoVO) {
		// 调用框架自带的dto<-->pojo 映射方法创建Entity实例
		OrderInfo orderInfoEntity = lightDao.convertType(orderInfoVO, OrderInfo.class);
		// 调用save完成保存
		lightDao.save(orderInfoEntity);
	}

	// 复杂查询通过sql.xml 定义具体sql内容
	@Override
	public Page<OrderInfoVO> searchOrderInfo(Page pageModel, Map queryMap) {
		String sql = """
				select * from SQLTOY_ORDER_INFO t
				where 1=1
				#[and t.status in (:statusAry)]
				#[and t.create_time>=:beginTime]
				#[and t.create_time<=:endTime]
				""";
		return lightDao.findPage(pageModel, sql, queryMap, OrderInfoVO.class);
	}

}
